﻿using ETHotfix;
using ETModel;
using System;
using System.Threading;
using ZGameSurvival.Model;

namespace ZGameSurvival.Start {
    class Program {
        private static string UserHotfixDllFilePath = "./ZGameSurvival.Hotfix.dll";
        private static string UserHotfixPdbFilePath = "./ZGameSurvival.Hotfix.pdb";

        private static void Main(string[] args) {

            //控制台调用例子
            try {
                //初始化服务管理器
                ServerManager.Init(UserHotfixDllFilePath, UserHotfixPdbFilePath);

                //初始化物理引擎库
                BulletHelper.Init();

                //加载配置
                Options options = Game.Scene.AddComponent<OptionComponent, string[]>(args).Options;
                StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
                if (!options.AppType.Is(startConfig.AppType)) {
                    Log.Error("命令行参数apptype与配置不一致");
                    return;
                }

                switch (startConfig.AppType) {
                    case AppType.AllServer:
                        // allserver一般为调试,需要控制台输出等交互
                        Game.Scene.AddComponent<ConsoleComponent>();
                        break;
                }
                //初始化服务管理器
                AutoResetEvent loopEndEvent = new AutoResetEvent(false);

                //开始当前配置的服务消息循环
                ServerManager.StartServerLoopByConfig<NetOuterComponent>(typeof(ModelInit).Assembly, startConfig, loopEndEvent);
            } catch (Exception e) {
                Log.Error(e);
            }

        }
    }
}
